find_package(libpng CONFIG CONFIGS libpng16.cmake)

message("libpng_ROOT:${libpng_ROOT}")

if(libpng_FOUND)
  get_target_property(libpng_LIBRARY png_shared IMPORTED_LOCATION)  
  if(NOT libpgn_LIBRARY)
    get_target_property(libpng_LIBRARY png_shared IMPORTED_LOCATION_RELEASE)
  endif()
  set(_png_root "${libpng_LIBRARY}/../..")
  find_path(libpng_INCLUDE_DIR png.h
    HINTS ${_png_root}
    PATH_SUFFIXES include)
  target_include_directories(png_shared INTERFACE ${libpng_INCLUDE_DIR})
  target_include_directories(png_static INTERFACE ${libpng_INCLUDE_DIR})
endif()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(libpng
  REQUIRED_VARS libpng_LIBRARY libpng_INCLUDE_DIR
  CONFIG_MODE)

if(libpng_FOUND)
  set(libpng_INCLUDE_DIRS ${libpng_INCLUDE_DIR})
  set(libpgn_LIBRARIES ${libpng_LIBRARY})
endif()